/*
 * @Author: szx
 * @Date: 2022-05-13 14:47:11
 * @LastEditTime: 2022-05-13 14:50:58
 * @Description:
 * @FilePath: \leetcode\面试题\02\01\02.js
 */

/**
 * @param {ListNode} head
 * @param {number} k
 * @return {number}
 */
 var kthToLast = function (head, k) {
    let next = head;
    while (k-- > 0) next = next.next;
    let res = head;
    while (next) {
        res = res.next;
        next = next.next;
    }
    return res.val;
};